<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("comctrls.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Change_Stat extends Page
{
       function Change_StatCreate($sender, $params)
       {
       $autoid = base64_decode($_GET['autoid']);
       $query_queue = "SELECT * FROM queue_tbl WHERE autoid='".$autoid."'";
       $result_queue = mysql_query($query_queue) or die("SELECT QUEUE ".mysql_error());
       $row_queue = mysql_fetch_array($result_queue);

       $stat = $row_queue['status'];
       //die($query_queue);
       if($stat=='inline')
       {
       $new_stat = 'loading';
       }

       if($stat=='loading')
       {
       $new_stat = 'loaded';
       }

       if($stat=='loaded')
       {
       $new_stat = 'intransit';
       }

       if($stat=='intransit')
       {
       $new_stat = 'complete';
       }
       //die($new_stat);

       $curr_timestamp = date('Y-m-d H:i:s');

       if($new_stat=='loading')
       {
       $query_update = "UPDATE queue_tbl set status='".$new_stat."',
       loading_timestamp = '".$curr_timestamp."' where autoid='".$autoid."'";
       mysql_query($query_update)or die("UPDATE QUEUE - " . mysql_error());
       }

       if($new_stat=='loaded')
       {
       $query_update = "UPDATE queue_tbl set status='".$new_stat."',
       loaded_timestamp = '".$curr_timestamp."'where autoid='".$autoid."'";
       mysql_query($query_update)or die("UPDATE QUEUE - " . mysql_error());
       }

       if($new_stat=='intransit')
       {
       $query_update = "UPDATE queue_tbl set status='".$new_stat."',
       intransit_timestamp = '".$curr_timestamp."'where autoid='".$autoid."'";
       mysql_query($query_update)or die("UPDATE QUEUE - " . mysql_error());
       }
       if($new_stat=='complete')
       {
       $query_update = "UPDATE queue_tbl set status='".$new_stat."',
       complete_timestamp = '".$curr_timestamp."'where autoid='".$autoid."'";
       mysql_query($query_update)or die("UPDATE QUEUE - " . mysql_error());
       }


       //die($query_update);
       echo"<script language=javascript>
       alert('Successfully changed status to ".$new_stat."!');
       window.location.href='queue_list.php';
       </script>";

       //redirect('queue_list.php');
       }

}

global $application;

global $Change_Stat;

//Creates the form
$Change_Stat=new Change_Stat($application);

//Read from resource file
$Change_Stat->loadResource(__FILE__);

//Shows the form
$Change_Stat->show();

?>